//引入vue
import Vue from "vue"
//引入vuex
import Vuex from "vuex"
import axios from "axios"

//在vue中使用插件
Vue.use(Vuex)
    
//在外面配置数据 
const state ={
    count : 0,
    price:99,
    movieList:[]
}

const mutations = {
    increament(state){
        state.count++
    },
    //payload是个对象 可以传跟多的值
    increamentN(state,{n,m}){
        state.count+=n+m
    },
    getList(state,payload){
        state.movieList = payload
    }
}

 const actions={
   async  getmoveList({commit}){
      const result= await  axios.get("https://pcw-api.iqiyi.com/search/recommend/list?channel_id=1&data_type=1&mode=11&page_id=2&ret_num=48&session=b9fd987164f6aa47fad266f57dffaa6a");
      commit("getList",result.data.data.list)
    }
}

const getters = {
    mymoveList(state){
        return state.movieList.filter(item=>{
            return item.albumName.length<7 &&item.albumName.length>4
        })
    },
    yourmovieList(state){
        return ({n,m})=>{
            return state.movieList.filter(item=>{
                return item.albumName.length<m &&item.albumName.length>n
            })
        }
    }
}
//暴露store
export default  new Vuex.Store({
    state,
    mutations,
    actions,
    getters
})